/*
 * @Descripttion: localStorage存取方法封装
 * @Author: sichuntian
 * @Date: 2021-11-23 23:01:42
 */


const namespace = 'pc';

//存值
export function saveItem (key, value) {
  let storage = window.localStorage.getItem(namespace);

  if (!storage) {
    storage = {};
  } else {
    storage = JSON.parse(storage)
  }

  storage[key] = value;
  window.localStorage.setItem(namespace, JSON.stringify(storage))
}

//取值
export function loadItem (key, def) {
  let storage = window.localStorage.getItem(namespace);

  if (!storage) {
    return def;
  }

  storage = JSON.parse(storage);
  let result = storage[key];
  return result || def;
}

